package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mapper.SettingsMapper;
import com.tanhua.model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/11/30 0:24
 */

@DubboService
public class SettingsApiImpl implements SettingsApi{
    
    @Autowired
    private SettingsMapper settingsMapper;

    /**
     * 按照用户id查询settings
     * @param userId
     * @return
     */
    @Override
    public Settings findByUserId(Long userId) {

        LambdaQueryWrapper<Settings> queueWrapper = new LambdaQueryWrapper<>();
        queueWrapper.eq(Settings::getUserId, userId);
        Settings settings = settingsMapper.selectOne(queueWrapper);
        return settings;
    }

    /**
     * 保存推送开关状态
     * @param settings
     */
    @Override
    public void save(Settings settings) {
        settingsMapper.insert(settings);
    }

    /**
     * 修改推送开关
     * @param settings
     */
    @Override
    public void updateByUserId(Settings settings) {

        LambdaQueryWrapper<Settings> queueWrapper = new LambdaQueryWrapper<>();
        queueWrapper.eq(Settings::getUserId, settings.getUserId());
        settingsMapper.update(settings, queueWrapper);
    }


}
